package com.societyGames.outputExercises
{
import com.societyGames.action.ActionQueue;

import flash.display.Sprite;

public class OutputSimulation
{
  private var _sprite:Sprite = new Sprite();
  private var _render:OutputRender;
  private var _actionQueue:ActionQueue;
  private var _outputText:String = "";

  public var desiredText:String;

  public function get sprite():Sprite
  {
    return this._sprite;
  }

  public function initialize(actionQueue:ActionQueue):void
  {
    this._actionQueue = actionQueue;

    //Render
    this._render = new OutputRender(this, this._actionQueue);
    this._sprite.addChild(this._render);

    //Show desired text.
    this._render.setDesiredText(this.desiredText);
  }

  public function get render():OutputRender
  {
    return _render;
  }

  public function doesTextMatch():Boolean
  {
    return desiredText == _outputText;
  }

  public function renderOutputText(text:String):void
  {
    this._render.addOutputText(text);
  }

  public function addOutputText(text:String):void
  {
    if (_outputText != null && _outputText.length > 0)
    {
      text = "\n" + text;
    }
    _outputText += text;
  }
}
}